<%@ include file="/WEB-INF/jsp/common/taglibs.jsp"%>
<%@ include file="/WEB-INF/jsp/common/jslibs.jsp"%>

<style>
.section{
	padding: 10px 0px 10px 50px;
	margin: 10px 0px 10px 0px; 
	background-color : #F4F4F4;
	border: 5px solid #666666;
	background-color: #F4F4F4;
}
#banner  {
	height: 1000px;
}
#tile  {
	height: 1800px;
}

.banner-wrapper {
	padding: 10px 0px 30px 0px;
	float: left;	
	width: 100%;
}
.banner-input-wrapper {
	float: left;
	width: 65%;
}
.banner-current-bg-image{
	display: inline;
}
.banner-input {
	margin-bottom: 5px;
}
.tab-title{
	font-size: 30px;
}
.submit-button{
	width: 100px;
	height: 50px;
	margin-top: 10px;
}
</style>

<c:set var="numOfBanners" value="4" />
<c:set var="numOfTabs" value="2" />
<c:set var="numOfTilesPerTab" value="4" />

<div id="mainContent">

	<form:form method="post" action="${contextPath}/admin/personal/mobile/submit" modelAttribute="adminPersonalMobileForm" enctype="multipart/form-data">
		<input type="submit" value="Submit" class="submit-button"/>
		<!-- BEGIN BANNER SECTION -->		
		<div id="banner" class="section">
			<h1>Configuration of the BANNER section</h1>
			<c:forEach items="${bannerList}" var="banner" varStatus="bannerStatus">
				<c:choose>
					<c:when test="${bannerStatus.count le numOfBanners}">
						<div class="banner-wrapper">
							<div class="banner-input-wrapper">
								<input type="hidden" name="bannerList[${bannerStatus.count-1}].id" value="${banner.id}"/>
								<input type="hidden" name="bannerList[${bannerStatus.count-1}].bgImageLink" value="${banner.bgImageLink}"/>
								<div class="banner-input">
									<span>Banner ${bannerStatus.count} Title: </span>
									<input name="bannerList[${bannerStatus.count-1}].title" type="text" maxlength="1000" value="<c:out value="${banner.title}"/>"/>
								</div>
								<div class="banner-input">
									<span>Banner ${bannerStatus.count} Link: </span>
									<input name="bannerList[${bannerStatus.count-1}].link" type="text" maxlength="1000" value="<c:out value="${banner.link}"/>"/>
								</div>
								<div class="banner-input">
									<span>Banner ${bannerStatus.count} Text: </span>
									<textarea rows="6" cols="22" name="bannerList[${bannerStatus.count-1}].text" maxlength="1000"><c:out value="${banner.text}"/></textarea>
								</div>
								<div class="banner-input">
									<span>Banner ${bannerStatus.count} background image (If not upload any new image, the old image will be used): </span>
									<input name="bannerBgImageList[${bannerStatus.count-1}]" type="file" accept="image/*"/>
								</div>
							</div>
							<div class="banner-current-bg-image">
									<img width="200" height="100" alt="missing current banner image" src="<c:url value="${banner.bgImageLink}"/>">
							</div>
						</div>
					</c:when>
					<c:otherwise></c:otherwise>
				</c:choose>
			</c:forEach>
		</div>
		<!-- END BANNER SECTION -->
		
		<!-- BEGIN TILE SECTION -->
		<div id="tile" class="section">
			<h1>Configuration of the TILE section</h1>
			<c:forEach items="${tabList}" var="tab" varStatus="tabStatus">
				<c:choose>
					<c:when test="${tabStatus.count le numOfTabs}">
						<div>
							<span class="tab-title">${tabStatus.count}. <c:out value="${tab.title}"/></span>	
							<input type="hidden" name="tabList[${tabStatus.count-1}].id" value="${tab.id}"/>							
							
							<input type="text" name="tabList[${tabStatus.count-1}].title" value="${tab.title}" style="margin-left: 20px"/>
							
							<c:forEach items="${tab.tabTiles}" var="tile" varStatus="tileStatus">
								<c:choose>
									<c:when test="${tileStatus.count le numOfTilesPerTab}">
											<div class="banner-wrapper">
												<div class="banner-input-wrapper">
													<input type="hidden" name="tabList[${tabStatus.count-1}].tabTiles[${tileStatus.count-1}].id" value="${tile.id}"/>
													<input type="hidden" name="tabList[${tabStatus.count-1}].tabTiles[${tileStatus.count-1}].imageLink" value="${tile.imageLink}"/>
													<div class="banner-input">
														<span>Tile ${tileStatus.count} Title: </span>
														<input name="tabList[${tabStatus.count-1}].tabTiles[${tileStatus.count-1}].title" type="text" maxlength="1000" value="<c:out value="${tile.title}"/>"/>
													</div>
													<div class="banner-input">
														<span>Tile ${tileStatus.count} Link: </span>
														<input name="tabList[${tabStatus.count-1}].tabTiles[${tileStatus.count-1}].link" type="text" maxlength="1000" value="<c:out value="${tile.link}"/>"/>
													</div>
													<div class="banner-input">
														<span>Tile ${tileStatus.count} Text: </span>
														<textarea rows="4" cols="22" name="tabList[${tabStatus.count-1}].tabTiles[${tileStatus.count-1}].text" maxlength="1000" ><c:out value="${tile.text}"/></textarea>
													</div>
													<div class="banner-input">
														<span>Tile ${tileStatus.count} image (If not upload any new icon, the old icon will be used): </span>
														<c:set var="tileIndex" value="${(tabStatus.count -1) * numOfTilesPerTab +  tileStatus.count - 1}"/>														
														<input name="tileImageList[${tileIndex}]" type="file" accept="image/*"/>
													</div>
												</div>
												<div class="banner-current-bg-image">
													<img width="175" height="60" alt="missing current tile image" src="<c:url value="${tile.imageLink}"/>">
												</div>
											</div>
									</c:when>
								</c:choose>
							</c:forEach>
						</div>
					</c:when>
				</c:choose>
			</c:forEach>
		</div>
		<!-- END TILESECTION -->
		
		<input type="submit" value="Submit" class="submit-button"/>
	</form:form>
</div>